
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#include "GRTToolBar.h"

#include <QAction>
#include "GRTMemoryLeak.h"
//constructor
GRTToolBar::GRTToolBar(QWidget* parent) : QToolBar(parent)
{
	//translate button
	QIcon* translateIcon = new QIcon(":/image/Resources/move.png");
	_translateButton = new QAction(*translateIcon, "Translate (T)", this);
	_translateButton->setCheckable(true);
	addAction(_translateButton);
	
	//rotate button
	QIcon* rotateIcon = new QIcon(":/image/Resources/rotate.png");
	_rotateButton = new QAction(*rotateIcon, "Rotate (R)", this);
	_rotateButton->setCheckable(true);
	addAction(_rotateButton);

	//scale button
	QIcon* scaleIcon = new QIcon(":/image/Resources/scale.png");
	_scaleButton = new QAction(*scaleIcon, "Scale (S)", this);
	_scaleButton->setCheckable(true);
	addAction(_scaleButton);

	//separator
	addSeparator();

	//add vertex to mesh
	_addVertexButton = new QAction("Add Vertex", this);
	addAction(_addVertexButton);

	//button to delete a vertex from a mesh
	_deleteVertexButton = new QAction("Delete Vertex", this);
	addAction(_deleteVertexButton);

	//button to merge two vertices
	_mergeVertexButton = new QAction("Merge Vertices", this);
	addAction(_mergeVertexButton);

}

//destructor
GRTToolBar::~GRTToolBar()
{

}

void GRTToolBar::uncheckAllButTranslate()
{
	_rotateButton->setChecked(false);
	_scaleButton->setChecked(false);
}

//uncheck all the buttons except the rotation button
void GRTToolBar::uncheckAllButRotate()
{
	_translateButton->setChecked(false);
	_scaleButton->setChecked(false);
}

//uncheck all the buttons except the scale button
void GRTToolBar::uncheckAllButScale()
{
	_translateButton->setChecked(false);
	_rotateButton->setChecked(false);
}

//check the translation button
void GRTToolBar::checkTranslateButton()
{
	_translateButton->setChecked(true);
}

//toggle translate button
void GRTToolBar::toggleTranslateButton()
{
	if(_translateButton->isChecked())
	{
		_translateButton->setChecked(false);
		_rotateButton->setChecked(false);
		_scaleButton->setChecked(false);
	}
	else
	{
		_translateButton->setChecked(true);
		_rotateButton->setChecked(false);
		_scaleButton->setChecked(false);
	}
}

//toggle the rotation button
void GRTToolBar::toggleRotateButton()
{
	if(_rotateButton->isChecked())
	{
		_rotateButton->setChecked(false);
		_translateButton->setChecked(false);
		_scaleButton->setChecked(false);
	}
	else
	{
		_rotateButton->setChecked(true);
		_translateButton->setChecked(false);
		_scaleButton->setChecked(false);
	}
}

//toggle the rotation button
void GRTToolBar::toggleScaleButton()
{
	if(_scaleButton->isChecked())
	{
		_rotateButton->setChecked(false);
		_translateButton->setChecked(false);
		_scaleButton->setChecked(false);
	}
	else
	{
		_rotateButton->setChecked(false);
		_translateButton->setChecked(false);
		_scaleButton->setChecked(true);
	}
}